package consume.topic;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author : xiaohong
 * @date : 2021/4/11 15:35
 */

@Component
public class TopicConsumer {

    @RabbitListener(queues = {"topic1"})
    public void receive1(Channel channel, String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        System.out.println("topic1接收到消息：  "+message);
        channel.basicAck(tag,true);
    }

    @RabbitListener(queues = {"topic2"})
    public void receive2(Channel channel, String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        System.out.println("topic2接收到消息：  "+message);
        channel.basicAck(tag,true);
    }

    @RabbitListener(queues = {"topic3"})
    public void receive3(Channel channel, String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        System.out.println("topic3接收到消息：  "+message);
        channel.basicAck(tag,true);
    }

    @RabbitListener(queues = {"topic4"})
    public void receive4(Channel channel, String message, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws IOException {
        System.out.println("topic4接收到消息：  "+message);
        channel.basicAck(tag,true);
    }

}
